package com.cht.commonUtil.svn;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cht.commonUtil.structure.L1S1;
import com.cht.commonUtil.webInit.SP;
import com.cht.commonUtil.widgets.Widgets;
import com.google.gson.Gson;

public class ChkFileRevision extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding(SP.UIcodeSet);
		response.setCharacterEncoding(SP.UIcodeSet);
		response.setContentType("application/json");

		String svnUrl = request.getParameter("url");
		boolean isMR = Boolean.parseBoolean( request.getParameter("isMR") );
		String svnUSR = request.getParameter("usr");
		String svnPWD = request.getParameter("pwd");
		String relativePath = request.getParameter("relativePath");
		String fileName = request.getParameter("fileName");

		if (svnUrl.lastIndexOf("/") != svnUrl.length() - 1) {
			svnUrl += "/";
		}
		List<L1S1> verSet = new ArrayList<L1S1>();

		System.out.println("isNeedQAqualified:"+SP.isNeedQAqualified);
		
		try {
			if (SP.isNeedQAqualified) {
				verSet = Widgets.getDeployedVersion(svnUrl, fileName);
			} else {
				verSet = Widgets.chkFileRevisionAndComment(isMR, svnUrl, svnUSR,svnPWD, relativePath, fileName, false);
			}
		} catch (Exception e) {
			Widgets.errLog(e);
		}

		response.getWriter().write(new Gson().toJson(verSet));
	}

}
